<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="shortcut icon" href="../images/favicon.ico">
    <link rel="apple-touch-icon-precomposed" href="../images/apple-touch-icon.png">
    <title>dragrefresh</title>
    <link rel="stylesheet" href="../scripts/lib/seedsui/seedsui.min.css">
</head>

<body ontouchstart="">
    <!-- <section> -->
        <header>
            <div class="titlebar">
            	<a class="titlebar-button" href="javascript:back()"><i class="icon icon-arrowleft"></i></a>
                <h1 class="titlebar-title">下拉刷新</h1>
            </div>
        </header>
        <article>
            <hr/>
            <ul class="list" id="list"></ul>
        </article>
    <!-- </section> -->
    <script src="../scripts/lib/seedsui/seedsui.min.js"></script>
    <!--Exmobi能力-->
    <!--<script src="../scripts/lib/exmobi/exmobi.js"></script>-->
    <script type="text/javascript">

        var view={
            /*=========================
              Model
              ===========================*/
            render:function(){
                var self = this;
                this.pagination={
                    count:5,
                    current:0
                }
                //插件
                this.drag=DfPull({
                    overflowContainer:document.body,
                    //overflowContainer:"article",
                    //topContainer:false,
                    //bottomContainer:false,
                    parent:"article",
                    onTopRefresh:function(e){
                        console.log("头部刷新");
                        self._loadData();
                    },
                    onTopComplete:function(e){
                        console.log("头部完成");
                    },
                    onBottomRefresh:function(e){
                        console.log("底部刷新");
                        self._loadNextPage();
                    },
                    onBottomComplete:function(e){
                        console.log("底部完成");
                    },
                    onBottomNoData:function(e){
                        console.log("底部无数据了");
                    }
                });

                //渲染页面
                
                //加载数据
                this._loadData();

                this._attach();//使用backbone时，此行无用
            },
            refresh:function(){
                console.log("刷新");
            },
            destroy:function(){
                console.log("移除");
            },
            
            /*=========================
              Method
              ===========================*/
            _loadData:function(){
                var self=this;
                var liStr="";
                for(var i=0;i<20;i++){
                    liStr+='<li class="underline" style="padding:12px 10px;"><p>第'+i+'行列表</p></li>';
                }
                setTimeout(function(){
                    document.querySelector(".list").innerHTML=liStr;
                    self.pagination.current=1;
                    //drag标识头部状态
                    self.drag.topComplete();
                }, 2000);
            },
            _loadNextPage:function(){
                var self=this;
                if(this.pagination.current==this.pagination.count){
                    //drag标识底部状态
                    this.drag.bottomNoData();
                    return;
                }
                var liStr="";
                for(var i=0;i<10;i++){
                    liStr+='<li class="underline" style="padding:12px 10px;"><p>第'+i+'行列表</p></li>';
                }
                
                setTimeout(function(){
                    document.querySelector(".list").innerHTML+=liStr;
                    self.pagination.current++;
                    //drag标识底部状态
                    self.drag.bottomComplete();
                }, 500);
            },
            /*=========================
              Events
              ===========================*/
            _attach:function(e){
            },
            /*=========================
              Event Handler
              ===========================*/
        }

        window.addEventListener("load",function(){
            view.render();
        }, false);
        
        //定义exmobi返回
        function back(){history.go(-1);}
    </script>
</body>
</html>
